@extends('admin.main')
@section('content')
    <div class="admin-content">
        <div class="am-cf am-padding am-padding-bottom-0">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">后台设置</strong> /
                <small>企业资料</small>
            </div>
        </div>
        <hr>
        <div class="am-g">
            @include('admin.layouts.adminInfo')
            <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
                <form action="{{$prefix_url}}{{isset($data)?'/'.$data->id:''}}"
                      class="am-form" method="POST" enctype="multipart/form-data">
                    {{csrf_field()}}
                    <input type='hidden' name='_method' value='POST'/>
                    <input type='hidden' name='cid' value='{{isset($data->cid)}}'/>
                    <div class='am-form-group'>
                        <label>企业选择【必填】：</label>
                        <select name="cid" required>
                            @if(count($coms))
                                @foreach($coms as $com)
                            <option value="{{$com['uid']}}"
                                    @if(isset($data)&&$data->cid==$com['uid'])
                                        selected
                                    @endif
                                >
                                {{$com['uid']}}
                                -
                                {{$com['name']}}
                            </option>
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>岗位选择【必填】：</label>
                        <select name="job" required>
                            @if(isset($data))
                            @endif
                            <option value="0">选择</option>
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>招聘人数【必填】：</label>
                        <input type="text" name="num" placeholder="招聘人数" pattern="\d+" required value="{{isset($data)?$data->num:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>薪酬【必填】：</label>
                        <input type="text" name="emolument" placeholder="薪酬待遇" pattern="\d+" required value="{{isset($data)?$data->emolument:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>福利待遇【必填】：</label>
                        <br>
                        @foreach($welfares as $key => $welfare)
                        <label>
                            <input type="radio" name="welfare" value="{{$key}}"
                                    {{(isset($data)&&$data->welfare==$key)?'checked':''}}>
                            {{$welfare}}
                        </label>
                        &nbsp; &nbsp;
                        @endforeach
                    </div>
                    <div class='am-form-group'>
                        <label>休息制度【必填】：</label>
                        <br>
                        @foreach($rests as $key => $rest)
                        <label>
                            <input type="radio" name="rest" value="{{$key}}"
                                    {{(isset($data)&&$data->rest==$key)?'checked':''}}>
                            {{$rest}}
                        </label>
                        &nbsp; &nbsp;
                        @endforeach
                    </div>
                    <div class='am-form-group'>
                        <label>性别【必填】：</label>
                        <br>
                        <label>
                            <input type="radio" name="sex" value="1"
                                    {{(isset($data)&&$data->sex==1)?'checked':''}}>
                            男
                        </label>
                        &nbsp; &nbsp;
                        <label>
                            <input type="radio" name="sex" value="2"
                                    {{(isset($data)&&$data->sex==2)?'checked':''}}>
                            女
                        </label>
                    </div>
                    <div class='am-form-group'>
                        <label>学历【必填】：</label>
                        <select name="edu" required>
                            @if(count($edus))
                                @foreach($edus as $key => $edu)
                                    <option value="{{$key}}"
                                            @if(isset($data)&&$data->education==$key)
                                                selected
                                            @endif
                                        >
                                        {{$edu}}
                                    </option>
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>工作年限【必填】：</label>
                        <select name="workYear" required>
                            @if(count($workYears))
                                @foreach($workYears as $key => $workYear)
                                    <option value="{{$key}}"
                                            @if(isset($data)&&$data->work_year==$key)
                                                selected
                                            @endif
                                        >
                                        {{$workYear}}
                                    </option>
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class='am-form-group'>
                        <label>工作地点：</label>
                        <input type="text" name="address" placeholder="工作地点" minlength="2" value="{{isset($data)?$data->address:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>岗位要求：</label>
                        <textarea name="detail" placeholder="岗位要求">{{isset($data)?$data->detail:''}}</textarea>
                    </div>
                    <div class='am-form-group'>
                        <label>工作时间：</label>
                        <textarea name="workHour" placeholder="工作时间">{{isset($data)?$data->work_hour:''}}</textarea>
                    </div>
                    <div class='am-form-group'>
                        <label>联系人姓名：</label>
                        <input type="text" name="contactName" placeholder="联系人姓名" minlength="2" value="{{isset($data)?$data->contact_name:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>联系人号码：</label>
                        <input type="text" name="telephone" placeholder="联系人号码" minlength="2" value="{{isset($data)?$data->contact_telephone:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>邮箱地址：</label>
                        <input type="text" name="email" placeholder="邮箱地址" minlength="2" value="{{isset($data)?$data->email:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>年龄区间：</label>
                        <input type="text" name="ageStart" placeholder="起始年龄" pattern="\d+" value="{{isset($data)?$data->ageStart:''}}">
                        <input type="text" name="ageEnd" placeholder="结束年龄" pattern="\d+" value="{{isset($data)?$data->ageEnd:''}}">
                    </div>
                    <div class='am-form-group'>
                        <label>技术工种：</label>
                        <textarea name="skill" placeholder="技术工种">{{isset($data)?$data->skill:''}}</textarea>
                    </div>
                    <button type='button' class='am-btn am-btn-primary'
                            onclick='history.go(-1);'>返回</button>
                    <button type='submit' class='am-btn am-btn-primary'>
                        保存更新</button>
                </form>
                <br><br>
            </div>
        </div>
    </div>
    {{csrf_field()}}
    <input type="hidden" id="uid" value="{{isset($data)?$data->cid:0}}">

    <script type="text/javascript">
//        //日期组件
//        $(function() {
//            $('.doc-datepicker').datepicker().
//            on('changeDate.datepicker.amui', function(event) {
//                console.log(event.date);
//            });
//        });
        (function(){
            var uid = $('#uid').val();
            if (uid!=0) { getJobs(uid); }
        })();
        $('select[name="cid"]').on('change',function(){
            var uid = this.value;
            getJobs(uid);
        });
        /**
         * 获取岗位
         * */
        function getJobs(uid){
            var formData = {
                uid:uid
            };
            $.ajaxSetup({
                headers: { 'X-CSRF-TOKEN': $('input[name="_token"]').val() }
            });
            $.ajax({
                type:'post',
                url:getPrefix() + '/joblist-get',
                data:formData,
                success:function(res){
                    //console.log(res); return
                    if (res.code!=0) {
                        console.log(res); return
                    }
                    var resData = res.data;
//                    console.log(resData);
                    var i, h = '';
                    for (i=0;i<resData.length;i++) {
                        h += '<option value="'+resData[i].id+'">';
                        h += resData[i].name;
                        h += '</option>';
                    }
                    $('select[name="job"]').html(h);
                },
                error:function(){
                    console.log('操作失败！');
                }
            });
        }
        //请求地址
        function getPrefix(){
            return '/mcadmin/basic/job/company';
        }
    </script>
@stop